package apralms

class AdminFilters {

	def filters = {
		
		all(controller:'*', action:'*') {
			before = {
			}
			after = { Map model ->
			}
			afterView = { Exception e ->
			}
		}

		adminUserOnly(controller:'user',  action:"(list|show|create|delete|save)") {
			before = {
				if(!session?.user?.admin){
					flash.message = "权限不够，只限管理员才能操作。"
					redirect(controller:"user", action:"login")
					return false
				}
			}
		}
		
		adminOnly(controller:'*',  action:"(create|delete|save)") {
			before = {
				if(!session?.user?.admin){
					flash.message = "权限不够，只限管理员才能操作。"
					redirect(controller:"user", action:"login")
					return false
				}
			}
		}
		
		specialistOnly(controller:'*', action:'(edit|update)') {
			before = {
				if(!session?.user?.specialist){
					flash.message = "权限不够，只限管理员及专员才能操作。"
					redirect(controller:"user", action:"login")
					return false
				}
			}
		}

		staffOnly(controller:'*', action:"(list|show)") {
			before = {
				if(!session?.user?.staff){
					flash.message = "权限不够，只限注册人员才能操作。"
					redirect(controller:"user", action:"login")
					return false
				}
			}
		}
		
	}
}
